<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
</head>
<body>
    <div id="app">
        <!-- v-text、v-html -->
        <p>{{ msg }}</p>
        <p v-text="msg"></p>
        <p v-html="msg"></p>


        <!-- v-on -->
        <button v-on:click="show()">按钮1</button>
        <button v-on:click="show">按钮2</button>
        <button @click="show">按钮3</button>
        <button @click="print(25)">按钮4</button>
        <button @click="print(name)">按钮5</button>
        <button @click="print('笑文')">按钮6</button>
        <hr>


        <!-- v-show、v-if -->
        <button @click="change()">变1</button>
        <button @click="flag=!flag">变2</button>
        <!-- <p style="width: 100px; height: 100px; background: red;" v-show="flag">嘿嘿</p> -->
        <p style="width: 100px; height: 100px; background: red;" v-if="flag">嘿嘿</p>


        <!-- v-if、v-else-if、v-else -->
        <p v-if="age>=60">老年</p>
        <p v-else-if="age>=40">中年</p>
        <p v-else-if="age>=18">少年</p>
        <p v-else>童年</p>


        <!-- v-for -->
        <ul>
            <!-- <li v-for="item in names">{{ item }}</li> -->
            <li v-for="(item,index) in names">{{ index+1 }} - {{ item }}</li>
        </ul>


        <!-- v-bind -->
        <img v-bind:src="url" :width="width">

    </div>

    <script>
        var vm = new Vue({
            el: '#app',
            data: { // 数据仓库
                msg: '<h2>welcome to vue</h2>',
                name: '吴易',
                flag: true, // 控制显示隐藏
                age: 26,
                names: ['小王', '小李', '小张', '小赵'],
                url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png',
                width: '200px'
            },
            methods: { // 方法仓库
                show: function(){
                    console.log(111)
                },
                print: function(args){
                    console.log(args)
                    console.log(this == vm)
                    console.log(this) // 数据仓库中的变量，方法仓库中的方法，最终都会被放到Vue实例（this）中
                    console.log(this.name)

                    this.show() // 调用方法
                },
                change(){
                    this.flag = !this.flag
                }
            }
        })
    </script>
</body>
</html>